package com.xl.adminserver.v2.dispatch;

import com.google.common.collect.Maps;
import com.xl.adminserver.v2.sdkclients.ClientFactory;
import com.xl.adminserver.v2.sdkclients.SdkClient;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class CarDispatchAction {

    private Map<String, String> pileNoUrlCache = Maps.newHashMap();
    private Map<String, Object> clientCache = Maps.newHashMap();


    public SdkClient getDispatchClient(String pileNo) {
        String url = pileNoUrlCache.get(pileNo);
        if (url == null || url.isEmpty()) {
            SdkClient sdkClient = ClientFactory.createClient(url, SdkClient.class);
            clientCache.put(url, sdkClient);
            return sdkClient;
        }
        if (!clientCache.containsKey(url)) {
            SdkClient sdkClient = ClientFactory.createClient(url, SdkClient.class);
            clientCache.put(url, sdkClient);
            return sdkClient;
        }
        return (SdkClient) clientCache.get(url);
    }

}
